"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserModel = void 0;
const ErrorCode_1 = require("../config/ErrorCode");
const GameConfig_1 = require("../config/GameConfig");
const ServerConfig_1 = require("../config/ServerConfig");
const UserDao_1 = require("../dao/UserDao");
const ResponseModel_1 = require("./ResponseModel");
class UserModel {
    json2Model(data) {
        this.userid = data["userid"];
        this.account = data["account"];
        this.nick_name = data["userid"];
        this.token = data["token"];
        this.sex = data["sex"];
        this.headimg = data["headimg"];
        this.last_login_ip = data["last_login_ip"];
        this.state = data["state"];
        this.create_time = new Date(data["create_time"]).getTime();
        this.last_login_time = new Date(data["last_login_time"]).getTime();
    }
    static db2Model(data) {
        let model = new UserModel();
        model.json2Model(data);
        return model;
    }
    static login(account, token) {
        return __awaiter(this, void 0, void 0, function* () {
            let respModel = new ResponseModel_1.ResponseModel();
            let accountResult = yield UserDao_1.UserDao.get_user_data(account);
            if (accountResult) {
                if (ServerConfig_1.ServerConfig.nowServerConfig.status == ServerConfig_1.ServerConfig.Status_Type.Weihu) {
                    if (accountResult["state"] != GameConfig_1.GameConfig.Status_Type.Test) {
                        respModel.code = ErrorCode_1.ErrorCode.Code.Server_Weihu;
                        respModel.msg = ErrorCode_1.ErrorCode.code2Msg.get(respModel.code);
                    }
                }
                if (respModel.code == ErrorCode_1.ErrorCode.Code.Suc) {
                    if (token == accountResult["token"]) {
                        respModel.data = accountResult;
                    }
                    else {
                        respModel.code = ErrorCode_1.ErrorCode.Code.LoginError_token;
                        respModel.msg = ErrorCode_1.ErrorCode.code2Msg.get(respModel.code);
                    }
                }
            }
            else {
                respModel.code = ErrorCode_1.ErrorCode.Code.LoginError_NoUser;
                respModel.msg = ErrorCode_1.ErrorCode.code2Msg.get(respModel.code);
            }
            return respModel;
        });
    }
}
exports.UserModel = UserModel;
UserModel.State_Type = {
    FengJin: 0,
    Normal: 1,
    Test: 2, //测试账号
};
